﻿
namespace TwitterN.Views.User
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using System.Windows;
	using System.Windows.Controls;
	using System.Windows.Data;
	using System.Windows.Documents;
	using System.Windows.Input;
	using System.Windows.Media;
	using System.Windows.Media.Imaging;
	using System.Windows.Shapes;

	using Amplify.Twitter;

	/// <summary>
	/// Interaction logic for Login.xaml
	/// </summary>
	public partial class Login : Window
	{
		public Login()
		{
			InitializeComponent();
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			AccountClient client = new AccountClient(this.Username.Text.ToLower(), this.Password.Password);
			try
			{
				if (client.Verify().Authorized)
				{
					Properties.Settings.Default.Username = this.Username.Text;
					Properties.Settings.Default.Password = this.Password.Password;
					Twitter.SetCredentials(this.Username.Text, this.Password.Password);
					this.Close();
				}
				else
				{
					this.Message.Text = "The username and password was not authorized, please check both and try again";
				} 
				
			}
			catch (Exception ex)
			{
				this.Message.Text = ex.ToString();
			}
		}
	}
}
